#include<bits/stdc++.h>
int T;
int n ,m,L,V;
int d,v,a;
int p[10005];

int j_,k_,ans1,ans2,emm;
struct qujian{
int l,r;
}q[10005];
bool cmp(qujian a,qujian b){
    if(a.r==b.r){
        return a.l<b.l;
    }
    return a.r<b.r;
}
using namespace std;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        j_=0,k_=1;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++){
            cin>>d>>v>>a;
            if(v<=V&&a<=0){
                continue;
            }
            if(v<=V&&a>0)
            //v*v-V*V/(2.0*a)
            {
                q[j_++].l=d+(v*v-V*V+1)/(2*a)-1;
                q[j_].r=L;
            }
            if(v>V&&a<0){
                q[j_++].l=d;
                q[j_].r=d-(v*v-V*V+1)/(2*a)-1;
            }
            if(v>V&&a>=0){
                q[j_++].l=d;
                q[j_++].r=L;
            }
        }
        sort(q,q+j_,cmp);
        for(int i=0;i<j_;i++){
            cout<<q[i].l<<" "<<q[i].r<<"\n";
            }

        for(int i=0;i<=m;i++){
            cin>>p[i];
        }
        p[m+1]=9999999;
        sort(p+1,p+m+1);
        ans2=0,ans1=j_;
        for(int i=0;i<j_;){
            if(q[i].l<p[k_]&&q[i].l<p[k_+1]){
                i++;
                ans2++;
            }
            else if(q[i].r>p[k_]&&q[i].l<p[k_+1]){
                ans1--;
            }
            else{
                while(q[i++].r<p[k_]);
                k_++;
            }
        }
        cout<<ans1<<" "<<ans2;
    }

}
//diyibu,anshuruxeibianliang
